<?php
/**
 * Created by PhpStorm.
 * User: wangye
 * Date: 19-2-14
 * Time: 下午6:54
 */

//指定协议绑定ip等   协议,错误码,错误信息,udp必须指定的php常量
$socket = stream_socket_server("udp://127.0.0.1:1113",$erron,$errstr,STREAM_SERVER_BIND);

if (!$socket){
    dir("$errstr($erron)\n");
}
do{
    //监听客户端发送数据
    $data = stream_socket_recvfrom($socket,1024,0,$peer);//第四个存放发送客户端ip和端口 tcp无连接
    echo $data;
    stream_socket_sendto($socket,$data,0,$peer);
}while($data !== false);